/*
 * © 2010 Autodata Solutions Company. All Rights Reserved
 * This source code is the confidential and proprietary information of Autodata Solutions Company.
 * The user shall not, in whole or in part, copy, publish, disclose or make any use of this source code
 * without the prior written consent of Autodata Solutions Company.
 */
Ext.ns('net.autodata.compare');
(function () {
	
	var Store = new Ext.extend(Ext.data.Store, {
		constructor: function ()
		{
			Store.superclass.constructor.call(this, {
				autoLoad: false,
				reader: new Ext.data.JsonReader({
					idProperty: 'acode',
					root: 'rows',
					
					fields: [
						{name: 'acode'},
						{name: 'stockCount'},
						{name: 'startPrice'},
						{name: 'endPrice'},
						{name: 'url'}
					]
				})
			});
		}
	});
	
	/**
	 * Displays a collection of inventory records
	 * @class InventoryPanel
	 * @extends Ext.BoxComponent
	 * @namespace net.autodata.compare
	 */
	var Panel = Ext.extend(Ext.BoxComponent, {
		
		autoEl: {
			tag: 'div',
			cls: 'inventory-panel'
		},
		
		/**
		 * @property view
		 * @type Object
		 */
		view: undefined,
		
		store: undefined,
		
		width: 788,
		
		constructor: function ()
		{
			this.store = new Store();
			Panel.superclass.constructor.apply(this, arguments);
		},
		
		/**
		 * @method initCompeonent
		 */
		initComponent: function ()
		{	
			Panel.superclass.initComponent.apply(this, arguments);
			var view = this.getView();			
			this.relayEvents(view, ['infoclick']);
			view.init(this);
		},
		
		/**
		 * @method getView
		 */
		getView: function ()
		{
			if (!this.view) {
				this.view = new net.autodata.compare.InventoryView(this.viewCfg);
			}
			return this.view;
		},
		
		/**
		 * @method getStore
		 */
		getStore: function ()
		{
			return this.store;
		},
		
		/**
		 * @method render
		 */
		render: function ()
		{
			Panel.superclass.render.apply(this, arguments);
			this.getView().render();
		}
		
	});
	
	net.autodata.compare.InventoryPanel = Panel;
})();